<?php
require_once('./PHPMailer/class.phpmailer.php');



function sent_mail_by_gmail($email,$subject,$body) {
$smtp =array(
 array('user' =>'brandcial@gmail.com','pass' => 'business88'),
 array('user' =>'vinasale@gmail.com','pass' => 'business88'),
  array('user' =>'travel@vinabrand.com','pass' => 'business88'),
   array('user' =>'ecom@vinabrand.com','pass' => 'business88'),
    array('user' =>'info@vinabrand.com','pass' => 'business88'),
	 array('user' =>'tech@vinabrand.com','pass' => 'business88'),
	   array('user' =>'congnghe@vinabrand.com','pass' => 'business88'),
	    array('user' =>'xehoi@vinabrand.com','pass' => 'business88'),
 );
 
$rand = array_rand($smtp, 1);
$gsmtp = array();
$gsmtp['user'] = $smtp[$rand]['user'];
$gsmtp['pass'] = $smtp[$rand]['pass'];

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
  $mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->Port       = 465;    
       // set the SMTP port for the GMAIL server
  $mail->Username   = $gsmtp['user'];  // GMAIL username
  $mail->Password   = $gsmtp['pass'];            // GMAIL password
  
  $mail->SetFrom('info@vinabrand.com', 'Brand Express');
 $mail->AddReplyTo('info@vinabrand.com', 'Brand Express');
 $mail->Subject = $subject;
 $mail->MsgHTML($body);
  //////////////
 foreach($email as $to){
list($user_name, $mail_domain) = split("@",$to); // Split email address into username and domain name
   $mail->AddAddress($to,$user_name); 
//if($mail->Send() ){ echo "$to=>OK <br>";} else{ echo "error => $to <br>";} // echo error    
} // end foreach
 //////////////
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically 

} // end function;



function sent_mail_by_SMTP($email,$subject,$body) {
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
                               // 1 = errors and messages
                                           // 2 = messages only
$mail->Host       = "sapastay.com"; // SMTP server
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "localhost"; // sets the SMTP server
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "nhsaphxz"; // SMTP account username
$mail->Password   = "A3(~26Tl5wfk";        // SMTP account password
         
 $mail->SetFrom('info@vinabrand.com', 'Brand Express');
 $mail->AddReplyTo('info@vinabrand.com', 'Brand Express');
 $mail->Subject = $subject;
 $mail->MsgHTML($body);
  //////////////
 foreach($email as $to){
list($user_name, $mail_domain) = split("@",$to); // Split email address into username and domain name
   $mail->AddAddress($to,$user_name); 
//if($mail->Send() ){ echo "$to=>OK<br>";} else{ echo "error => $to<br>";} // echo error    
} // end foreach
 //////////////
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically 
} // end function;


function sent_mail_by_Sendmail($email,$subject,$body) {
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSendmail(); // telling the class to use SendMail transport

$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
                                          // 1 = errors and messages
                                       // 2 = messages only         
 $mail->SetFrom('info@vinabrand.com', 'Brand Express');
 $mail->AddReplyTo('info@vinabrand.com', 'Brand Express');
 $mail->Subject = $subject;
 $mail->MsgHTML($body);
  //////////////
 foreach($email as $to){
list($user_name, $mail_domain) = split("@",$to); // Split email address into username and domain name
   $mail->AddAddress($to,$user_name); 
  //if(!$mail->Send() ){$s = $s +1;} // echo error    
} // end foreach
 //////////////
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically 
 
} // end function;


function load_mail_list(){
global $max_mail_send;
$sendto = array();
$maillist = array();
        $loadmail = file_get_contents("mail.txt");
        $mail = explode(",", $loadmail);
 //$maillist = array_merge($maillist, $mail );
 $custom = str_replace(" ","",file_get_contents("mail/custom.txt"));
		$cusmail = explode(',',$custom);
$maillist = array_merge($maillist,$cusmail);

		if(count($maillist)>1){
	       $sendto = random_array($maillist,$max_mail_send);
		}else{
		$sendto = array('vinabrand@gmail.com');
		}
		return $sendto;
}

function load_rss_feed($feed_url){
$rss = new DOMDocument();
	$rss->load($feed_url);
	$feed = array();
	foreach ($rss->getElementsByTagName('item') as $node) {
		$item = array ( 
			'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
			'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
			'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
			'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
			);
		array_push($feed, $item);
	}
	return $feed;
}



function random_array($array,$n){
$new_array =array();

if($n<=count($array)){$i=$n;}else{$i=count($array);}
        $random = array_rand($array, $i);
		for ($i =0; $i<count($random); $i ++){
	  $new_array[$i] = $array[$random[$i]];
	  }
	  return $new_array;
}

?>